package EjerciciosNoBoletin1.Ex3;

public class Calculadora {
	
	private Float op1;
	private Float op2;
	
	public Calculadora(){
		op1 = new Float(0);
		op2 = new Float(0);
	}
	
	public Calculadora(Float op1,Float op2){
		this.op1 = op1;
		this.op2 = op2;
	}

	public Float getOp1() {
		return op1;
	}

	public void setOp1(Float op1) {
		this.op1 = op1;
	}

	public Float getOp2() {
		return op2;
	}

	public void setOp2(Float op2) {
		this.op2 = op2;
	}
	
	public Float Suma() throws MemoriaDesbordadaException{
		if (op1+op2 > 30){
			MemoriaDesbordadaException ex = new MemoriaDesbordadaException();
			throw ex;
		}
		return op1+op2;
	}
	
	public Float Resta() throws MemoriaDesbordadaException{
		if (op1+op2 < -30){
			MemoriaDesbordadaException ex = new MemoriaDesbordadaException();
			throw ex;
		}
		return op1-op2;
	}
	
	public Float Multiplicacion(){
		return op1*op2;
	}
	
	public Float Division(){
		
		Float retorno = null;
		
		if (op2 == 0) retorno = retorno.MAX_VALUE;
		else retorno = (float)op1/(float)op2;
		
		return retorno;
	}
	
	public Float[] realizarOperacion(Float valores[],char op){
		
		Float arr[] = new Float[3];
		
		Float result = new Float(0);
		
		Calculadora calc = new Calculadora();
		
		calc.setOp1(valores[0]);
		calc.setOp2(valores[1]);
		
		if (op == '+'){
			try{
				result = calc.Suma();
			} catch (MemoriaDesbordadaException ex){
				ex.printStackTrace();
			}
			
		}
		if (op == '-'){
			try{
				result = calc.Resta();
			} catch (MemoriaDesbordadaException ex){
				ex.printStackTrace();
			}
			
		}
		if (op == 'x'){
			result = calc.Multiplicacion();
		}
		if (op == '/'){
			result = calc.Division();
		}
		
		arr[0] = valores[0];
		arr[1] = valores[1];
		arr[2] = result;
		return arr;
	}
	
	public final void metodo(){
		
	}
	
	public static void metodo1(){
		System.out.println("Hola!");
		
		
	}
	
}
